<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../common/NavigationLeft.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>固定资产管理系统</title>
	<style type="text/css">
		.select2-container--open{
			z-index:9999999
		}
	</style>
</head>
<body style="height: 100%">
	<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
		<h2 class="page-header">资产操作日志列表</h2>
			<div class="row m-b-sm m-t-sm">
				<div class="col-md-1">
					<a><button type="button" id="refresh"
							class="btn btn-default btn-sm">刷新</button></a>
				</div>			
					<div class="col-md-4 f-r">
						<div class="input-group">
							<input type="text" id="searchTemp" class="form-control" value="${temp }" name="temp"
								placeholder="请输入设备型号/资产编号/使用人" style="height:30px;"> <span
								class="input-group-btn"><button
									class="btn btn-primary btn-sm" type="submit" id="search_btn">搜索</button> 
										<button class="btn btn-sm" type="button" id="more_search_btn">更多</button>
								</span>
						</div>
					</div>				
		  </div>
		  <form class="form-horizontal search_table">
			<div class="form-group col-md-4 col-sm-6 col-xs-12">
				<label class="col-sm-4 control-label">操作日期</label>
				<div class="col-sm-8 WdatePicker">
					<input id="opteTime1" class="form-control" type="datetime"
						placeholder="开始时间"
						onclick="WdatePicker({maxDate:'%y-%M-%d || #F{$dp.$D(\'opteTime2\')}'})" />
					- <input id="opteTime2" class="form-control" type="datetime"
						placeholder="结束时间"
						onclick="WdatePicker({minDate:'#F{$dp.$D(\'opteTime1\')}',maxDate:'%y-%M-%d'})" />
				</div>
			</div>
			<div class="form-group col-md-12 text-center m-t-sm">
				<button id="complex_search_btn" type="button"
					class="btn btn-sm btn-primary">查询</button>
				<button id="clear_btn" type="button" class="btn btn-sm btn-default ">清空</button>
			</div>
		</form>
			<div class="placeholder"></div>
		<form class="form-horizontal" action="genQRcode.action" method="post" id="asset_Form" target="_blank">
		<table id="listTable" class="table table-bordered table-striped table-hover" cellspacing="0">
			<thead>
				<tr>
				    <th>
						<input autocomplete="off" type="checkbox" id="CheckedAll"
						onclick="checkAll()">
					</th>
					<th>操作人员</th>					
					<th class="min-tablet-p dropdown selectdown">
                        <div class="table_dropdown dropdown">
						<a data-toggle="dropdown" class="dropdown-toggle" href="javascript:void(0);" >操作类型 <span class="caret"></span></a>	
						<ul role="menu" class="dropdown-menu">
                            <li class="active" value="" ><a href="javascript:void(0);">全部</a></li>
                            <li value="0"><a href="javascript:void(0);">添加</a></li>
                            <li value="1"><a href="javascript:void(0);">修改</a></li>
                            <li value="2"><a href="javascript:void(0);">分配</a></li>
                            <li value="3"><a href="javascript:void(0);">领用</a></li>
                            <li value="4"><a href="javascript:void(0);">归还</a></li>
                            <li value="5"><a href="javascript:void(0);">删除</a></li>
                        </ul>
                        </div>
                    </th>
					<th>资产编号</th>
					<th>设备型号</th>
					<th>操作日期</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
			
		</table>
		</form>
	</div>
<input id="userRole" type="hidden" value="${session.user.role}">
</body>
<script type="text/javascript">


 $(function(){
	var table = "";
	initTable();
	$("#search_btn").click(function(){
		initTable();
	});
	
	$("#refresh").click(function(){
		initTable();
	});
	
	$(".search_table").hide();
	$("#more_search_btn").click(function() {
		$(".search_table").toggle();
	});

	$("#complex_search_btn").click(function() {
		initTable();
	});

	$("#clear_btn").click(function() {
		$(".search_table input").each(function() {
			$(this).val("");
		})
	});
    
	//一个class中可以有多个类，中间用空格隔开	
	 $(document).on("click",".dropdown .dropdown-menu a",function(){
		$(this).parent().addClass("active").siblings().removeClass('active');
		$(".table_dropdown").removeClass("open");
		var opteGenre = $(this).parent().attr("value");
		initTable(opteGenre);
	});

	//初始化表格的方法，上面的事件中调用该方法
	function initTable(opteGenre) {
		var temp = $("#searchTemp").val();
		var opteTime1 = $("#opteTime1").val();
		var opteTime2 = $("#opteTime2").val();
		$.fn.dataTable.ext.errMode = function(s,h,m){
            layer.alert('数据加载失败');
        }
		 table = $('#listTable').DataTable( {
			 "destroy" : true,
			"paging" : true,
			"lengthChange" : true,
			"searching" : false,
			"ordering" : false,
			"info" : true,
			"autoWidth" : false,
			"Filter" : false,
			responsive : true,
			"pagingType" : "full_numbers",
			"dom" : 'rtilp',
			"language" : {
				"url" : "/static/js/datatables/jquery.dataTables.zh"
			},
	        "processing": true,
	        "serverSide": true,
	        "ajax": {
	   	          type: 'POST',  
	   	          url: 'ajax_assetListOperateData.action',  
	   	       	  data:{"temp":temp,"opteGenre":opteGenre,"opteTime1":opteTime1,"opteTime2":opteTime2},	   	      
	   	          timeout:60000  
	   	      },
	   	   "drawCallback":function () {
               $("#search_btn").click(function () {
                   table.page(table.page()).draw(false);
               });
	   	   },	    
	        "columns" : [
							{
								"data" : function(data,row) {
										return '<input autocomplete="off" name="checkedIds" type="checkbox" value="'+ data.id+'">';
								}
							},
							{
								"data" : function(data) {
									if(data.optePerson != null){
										return data.optePerson;
									}else{
										return "--";
									}
								}
							},
							{
								"data" : function(data) {
									if(data.opteGenre != null){
										return data.opteGenre;
									}else{
										return "--";
									}
								}
							},
							{
								"data" : function(data) {
									if(data.equipIdentifier != null){
										return data.equipIdentifier;
									}else{
										return "--";
									}
								}
							},
							{
								"data" : function(data) {
									if(data.equipModel != null){
										return data.equipModel;
									}else{
										return "--";
									}
								}
							},		
							{
								"data" : function(data) {
									if(data.opteTime != null){
										/* var now = new Date(data.opteTime);
										var nowStr = now.format("yyyy-MM-dd hh:mm:ss"); */
										return data.opteTime;
									}else{
										return "--";
									}
								}
							},							
							{
								"data" : function(data){
									
									/* 在session会话中的到登陆者身份 */
									var userRole = $("#userRole").val();

									if(userRole == "0"){
										
									return '<div class="btn-group">'+
									'<button data-toggle="dropdown"'+
										'class="btn btn-primary btn-xs dropdown-toggle" type="button">'+
										'<i class="fa fa-cog"></i> 操作 <span class="caret"></span>'+
									'</button>'+
									'<ul class="dropdown-menu">'+
										'<li><a class="" href="assetOperateInfo.action?id='+data.id+'">查看</a></li>'+
									'</ul>'+
								'</div>';
								}
							}
						}	
					]
	    	} );
		return table;
	}
})
 

$(function(){
	var tip="${tip}";
	if(tip!=""){
		layer.msg(tip,{area: ['300px','50px']});
	}
	$("#QRcode_btn").click(function() {
		var checkboxlen = 0;
		$("td :checkbox").each(function(index, ele) {
			if ($(this).prop("checked")) {
				checkboxlen++; 
			}
		});
		if(checkboxlen<1){
			layer.msg("至少勾选一项");
		}else{
			$("#asset_Form").submit();
		}
	});	
});



	//定义的方法：点击最上面的选择框，即把整个选择框全部选取
	function checkAll() {
		if ($("#CheckedAll").prop("checked")) {
			$(":checkbox").prop("checked", true);
		} else {
			$(":checkbox").prop("checked", false);
		}
	}
	//定义的方法：点击选择框，迭代出id
	function selectIds() {
		var assIds = new Array();
		var idString = "";
		$("td :checkbox").each(function(index, ele) {
			if ($(this).prop("checked")) {
				assIds.push($(this).attr("value"));
			}
		})
		for (var i = 0; i < assIds.length; i++) {
			idString = assIds[i] + "," + idString;
		}
		return idString;
	}
	
	//定义的方法：选择文件
	function changeFileName(){
		var filePath = $("#file").val();
		var fileName = filePath.substring(filePath.lastIndexOf("\\") + 1);
		$("#fileName").val(fileName);
		$("#file").parent().next().hide();
	}
	
	//对Date的扩展，将Date转化为指定格式的String
	Date.prototype.format = function(format){
		var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(), //day
		"h+" : this.getHours(), //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter 季度
		"S" : this.getMilliseconds() //millisecond 毫秒
		}

		if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
		}

		for(var k in o) {
			if(new RegExp("("+ k +")").test(format)) {
				format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
			}
		}
		return format;
	} 
</script>
</html>